let sweetAlert2Demo = function() {

    // Demos
    let initDemos = function() {
        // Sweetalert Demo 1
        $('#sweetalert-demo-1').click(function(e) {
            swal.fire('我是标题');
        });

        // Sweetalert Demo 2
        $('#sweetalert-demo-2').click(function(e) {
            swal.fire("我是标题", "Java是最好的语言");
        });

        // Sweetalert Demo 3
        $('#sweetalert-demo-3-1').click(function(e) {
            swal.fire("我是标题", "这是一个warning级别的提示", "warning");
        });

        $('#sweetalert-demo-3-2').click(function(e) {
            swal.fire("我是标题", "这是一个error级别的提示", "error");
        });

        $('#sweetalert-demo-3-3').click(function(e) {
            swal.fire("我是标题", "这是一个success级别的提示", "success");
        });

        $('#sweetalert-demo-3-4').click(function(e) {
            swal.fire("我是标题", "这是一个info级别的提示", "info");
        });

        $('#sweetalert-demo-3-5').click(function(e) {
            swal.fire("我是标题", "这是一个question级别的提示", "question");
        });

        // Sweetalert Demo 4
        $('#sweetalert-demo-4').click(function(e) {
            swal.fire({
                title: "我是标题",
                text: "我是消息内容",
                type: "success",
                buttonsStyling: false,
                confirmButtonText: "自定义按钮文字",
                confirmButtonClass: "btn btn-brand"
            });
        });

        // Sweetalert Demo 5
        $('#sweetalert-demo-5').click(function(e) {
            swal.fire({
                title: "我是标题",
                text: "我是消息内容",
                type: "success",

                buttonsStyling: false,

                confirmButtonText: "<i class='la la-headphones'></i> I am game!",
                confirmButtonClass: "btn btn-danger",

                showCancelButton: true,
                cancelButtonText: "<i class='la la-thumbs-down'></i> No, thanks",
                cancelButtonClass: "btn btn-default"
            });
        });

        $('#sweetalert-demo-6').click(function(e) {
            swal.fire({
                position: 'top-right',
                type: 'success',
                title: '你的数据已保存',
                showConfirmButton: false,
                timer: 3000
            });
        });

        $('#sweetalert-demo-7').click(function(e) {
            swal.fire({
                title: '我是标题',
                html: $('<div>')
                    .addClass('some-class')
                    .text('使用了animate.css提供的动画'),
                animation: false,
                customClass: 'animated tada'
            })
        });

        $('#sweetalert-demo-8').click(function(e) {
            swal.fire({
                title: '确定要删除吗？',
                text: "此操作无法撤销，请谨慎操作",
                type: 'warning',
                showCancelButton: true,
                confirmButtonText: '确定'
            }).then(function(result) {
                if (result.value) {
                    swal.fire(
                        '已删除',
                        '数据已成功删除',
                        'success'
                    )
                }
            });
        });

        $('#sweetalert-demo-9').click(function(e) {
            swal.fire({
                title: '确定要删除吗？',
                text: "此操作无法撤销，请谨慎操作",
                type: 'warning',
                showCancelButton: true,
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                reverseButtons: true
            }).then(function(result){
                if (result.value) {
                    swal.fire(
                        '已删除',
                        '数据已成功删除',
                        'success'
                    )
                    // result.dismiss can be 'cancel', 'overlay',
                    // 'close', and 'timer'
                } else if (result.dismiss === 'cancel') {
                    swal.fire(
                        '已取消',
                        '已取消删除',
                        'error'
                    )
                }
            });
        });

        $('#sweetalert-demo-10').click(function(e) {
            swal.fire({
                title: '我是标题',
                text: '使用自定义图片',
                imageUrl: '/assets/media/portrait/200*200-1.jpg',
                imageWidth: 200,
                imageHeight: 200,
                imageAlt: 'Custom image'
            });
        });

        $('#sweetalert-demo-11').click(function(e) {
            swal.fire({
                title: '自动关闭提示',
                text: '将会在5s后自动关闭',
                timer: 5000,
                onOpen: function() {
                    swal.showLoading()
                }
            }).then(function(result) {
                if (result.dismiss === 'timer') {
                    console.log('时间到自动关闭')
                }
            })
        });
    };

    return {
        init: function() {
            initDemos();
        }
    };
}();

$(document).ready(function() {
    sweetAlert2Demo.init();
});